import { SkillRuneHandbookTabData } from "../compose/SkillRuneHandbookTabData";
import { Dispatcher } from "../../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../../events/DataEvent";
import { EventName } from "../../../../mvc/EventName";
import { ObjCreate } from "../../../common/ObjCreate";
import { ResFileConst } from "../../../../resource/ResFileConst";
import { DataProvider } from "../../../../../../fl/data/DataProvider";
import { ScrollBarDirection } from "../../../../../../fl/controls/ScrollBarDirection";
import { ScrollPolicy } from "../../../../../../fl/controls/ScrollPolicy";
import { SkillRuneHandbookSubRender } from "./SkillRuneHandbookSubRender";
import { GLoadedButton } from "../../../../../../com/mui/controls/GLoadedButton";
import { GButton } from "../../../../../../com/mui/controls/GButton";
import { GTileList } from "../../../../../../com/mui/controls/GTileList";
import { GTextFiled } from "../../../../../../com/mui/controls/GTextFiled";
type int = number;
//class SkillRuneHandbookTabItem
    
    export  class SkillRuneHandbookTabItem /* flash.display.Sprite */
    {
        constructor(arg1: SkillRuneHandbookTabData)
        {
            
            this._data = arg1;
            this.initView();
            this._btn.addEventListener(flash.events.MouseEvent.CLICK, this.clickBtnHandler);
            return;
        }

        public get data(): SkillRuneHandbookTabData
        {
            return this._data;
        }

        public get myHeight(): number
        {
            return this._curHeight;
        }

        public get selectedIndex(): int
        {
            return this._list.selectedIndex;
        }

        public set selectedIndex(arg1: int)
        {
            this._list.selectedIndex = arg1;
            return;
        }

        public get selectedName(): string
        {
            var loc1=this.selectedIndex;
            if (loc1 >= 0 && loc1 < this._data.subNames.length) 
            {
                return this._data.subNames[loc1];
            }
            return "";
        }

        /* internal  */clickBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._isExpanded) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.RuneClickShrinRuneTypes, this._data));
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.RuneClickExpandRuneTypes, this._data));
            }
            return;
        }

        public get type(): int
        {
            return this._data.type;
        }

        public expandItem(): void
        {
            this._btnDec.visible = true;
            this._btnAdd.visible = false;
            this._txtName.textColor = 16711427;
            this._spExt.visible = true;
            this._curHeight = this._btn.height + (this.Gap + this.RowHeight) * this._data.subNames.length;
            this._isExpanded = true;
            return;
        }

        public shrinItem(): void
        {
            this._btnDec.visible = false;
            this._btnAdd.visible = true;
            this._txtName.textColor = 643342;
            this._spExt.visible = false;
            this._curHeight = this._btn.height;
            this._isExpanded = false;
            return;
        }

        /* internal  */initView(): void
        {
            this._btn = ObjCreate.createGLoadedButton(ResFileConst.TileBtn, 0, 0, 151, 25, this);
            this._btnDec = ObjCreate.createGButton("", 6, 11, 17, 4, this._btn, "SubBtnNoBg");
            this._btnAdd = ObjCreate.createGButton("", 6, 5, 14, 14, this._btn, "SupBtnNoBg");
            this._btnDec.mouseEnabled = false;
            this._btnAdd.mouseEnabled = false;
            this._txtName = ObjCreate.createGTextField("", 0, 5, 156, 20, this._btn);
            var loc1=this._txtName.defaultTextFormat;
            loc1.align = flash.text.TextFormatAlign.CENTER;
            loc1.size = 13;
            loc1.color = 643342;
            this._txtName.defaultTextFormat = loc1;
            this._txtName.text = this._data.name;
            this._txtName.mouseEnabled = false;
            this._spExt = new Object /* flash.display.Sprite */();
            this._spExt.x = 0;
            this._spExt.y = 27;
            this.addChild(this._spExt);
            var loc2=new DataProvider();
            var loc3=0;
            while (loc3 < this._data.subNames.length) 
            {
                loc2.addItem(this._data.subNames[loc3]);
                ++loc3;
            }
            this._list = ObjCreate.createTileList(0, 0, 151, 400, this._spExt);
            this._list.verticalGap = this.Gap;
            this._list.rowHeight = this.RowHeight;
            this._list.columnWidth = 150;
            this._list.direction = ScrollBarDirection.VERTICAL;
            this._list.scrollPolicy = ScrollPolicy.AUTO;
            this._list.setStyle("cellRenderer", SkillRuneHandbookSubRender);
            this._list.dataProvider = loc2;
            this._list.height = this._data.subNames.length * (this.Gap + this.RowHeight) + 2;
            this.shrinItem();
            return;
        }

        /* internal */ /* const */Gap: int=4;

        /* internal */ /* const */RowHeight: int=19;

        /* internal */ /* var */_btn: GLoadedButton;

        /* internal */ /* var */_btnAdd: GButton;

        /* internal */ /* var */_btnDec: GButton;

        /* internal */ /* var */_spExt: Object /* flash.display.Sprite */;

        /* internal */ /* var */_list: GTileList;

        /* internal */ /* var */_txtName: GTextFiled;

        /* internal */ /* var */_curHeight: int;

        /* internal */ /* var */_isExpanded: Boolean;

        /* internal */ /* var */_data: SkillRuneHandbookTabData;
    }
